package com.example.demo;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/*
 * Servlet 服务器HTTP响应
 * Web服务器响应一个HTTP请求时，响应通常包括一个状态行、一些响应抱头
 * 一个空行和文档。
 *
 * 自动刷新
 * 最简单setIntHeader()
 *
 * */

@WebServlet("/Refresh")
public class Refresh extends HttpServlet {

    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setIntHeader("Refresh", 5);
        resp.setContentType("text/html;charset=UTF-8");

        Calendar calendar = Calendar.getInstance();
        Date taskTime = calendar.getTime();
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String nowTime = df.format(taskTime);
        PrintWriter out = resp.getWriter();

        out.println("Current----> " + nowTime);
    }

    public void destroy() {

    }
}
